package project3;

/*
 *  Class for Open, Opened, and Open Failed cells
 */
public class OpenCell extends ConnectionCell {
	private long fromAgentId;
	private long toAgentId;	
	
	protected OpenCell(int circId, Util.CellType cellType) {
		super(circId, cellType);
		this.fromAgentId = -1;
		this.toAgentId = -1;
	}	
	
	public long getFromAgentId() {
		return this.fromAgentId;
	}
	
	public void setFromAgentId (int fromAgentId) {
		this.fromAgentId = fromAgentId;
	}
	
	public long getToAgentId() {
		return this.toAgentId;
	}
	
	public void setToAgentId (int toAgentId) {
		this.toAgentId = toAgentId;
	}
	
	public byte[] generateByteData() {
		byte[] ret = Util.generateHeader(this.circId, this.cellType, Util.CELL_LENGTH);
		
		// put fromAgentId to ret[3]~ret[6]
		for (int i = 3; i < 7; i++) {
			ret[i] = (byte) ((fromAgentId >> (6 - i) * 8) & 0xff);
		}
		
		// put toAgentId to ret[7]~ret[10]
		for (int i = 7; i < 11; i++) {
			ret[i] = (byte) ((toAgentId >> (10 - i) * 8) & 0xff);
		}
		
		return ret;
	}
}
